//
//  MainViewController.m
//  steamRoom
//
//  Created by 安建伟 on 2019/7/1.
//  Copyright © 2019 com.thingcom. All rights reserved.
//

#import "MainViewController.h"
#import "RDVTabBarController.h"
#import "RDVTabBarItem.h"
#import "MyDeviceViewController.h"
#import "MessageCenterController.h"
#import "PersonalCenterController.h"
#import "AppDelegate.h"

@interface MainViewController () <RDVTabBarControllerDelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    MyDeviceViewController *vc1 = [[MyDeviceViewController alloc] init];
    UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:vc1];
    
    MessageCenterController *vc2 = [[MessageCenterController alloc] init];
    UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:vc2];
    
    PersonalCenterController *vc3 = [[PersonalCenterController alloc] init];
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:vc3];
    
    self.viewControllers = @[nav1,nav2,nav3];
    [self navigationBarAppearance];
    [self customizeTabBarForController];
    
    self.selectedIndex = 0;
    self.delegate = self;
}

#pragma mark - customizeInterface
- (void)customizeTabBarForController{
    NSArray *tabBarItemTitle = @[@"我的设备",@"消息中心",@"个人中心"];
    NSArray *tabBarItemImages = @[@"img_tab_01_unselect",@"img_tab_02_unselect",@"img_tab_03_unselect"];
    NSArray *tabBarItemSelectImages = @[@"img_tab_01_select",@"img_tab_02_select",@"img_tab_03_select"];
    
    NSDictionary *tabBarTitleUnselectedDic = @{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"444444"],NSFontAttributeName:[UIFont systemFontOfSize:11]};
    NSDictionary *tabBarTitleSelectedDic = @{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"0576F6"],NSFontAttributeName:[UIFont systemFontOfSize:11]};
    
    NSInteger index = 0;
    for (RDVTabBarItem *item in self.tabBar.items) {
        item.tag = 1000 + index;
        UIImage *selectedImage = [UIImage imageNamed:[tabBarItemSelectImages objectAtIndex:index]];
        UIImage *unselectedImage = [UIImage imageNamed:[tabBarItemImages objectAtIndex:index]];
        [item setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
        
        item.selectedTitleAttributes = tabBarTitleSelectedDic;
        item.unselectedTitleAttributes = tabBarTitleUnselectedDic;
        [item setTitle:[tabBarItemTitle objectAtIndex:index]];
        index++;
    }
    
    [self.tabBar setHeight:tabbarHeight + ySafeArea_Bottom];
    self.tabBar.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0 + ySafeArea_Bottom / 3.f, 0);
    
    self.tabBar.translucent = YES;
    self.tabBar.backgroundView.backgroundColor = [UIColor colorWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1];
}

- (void)navigationBarAppearance{
    AppDelegate *delegate = (AppDelegate *)([UIApplication sharedApplication].delegate);
    
    delegate.navigationBarAppearance.translucent = NO;
    /** 设置导航栏背景图片 */
    [delegate.navigationBarAppearance setBackgroundImage:[UIImage imageNamed:@"background_navItem"] forBarMetrics:UIBarMetricsDefault];
    
    [delegate.navigationBarAppearance setTintColor:[UIColor whiteColor]];//返回按钮的箭头颜色
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
    NSDictionary *textAttributes = @{
                                     NSFontAttributeName: [UIFont systemFontOfSize:17.f],
                                     NSForegroundColorAttributeName: [UIColor whiteColor],
                                     };
    [delegate.navigationBarAppearance setTitleTextAttributes:textAttributes];
}

-  (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    
    return YES;
}

- (void)tabBarController:(RDVTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    
}

@end
